<article class="" id="post-">
<header class="entry-header">
<h1 class="entry-title">jQuery.type()</h1>
<div class="entry-meta">
						所属分类：<span class="category"><a href="/category/utilities/">工具类</a></span>
<span class="pull-right">英文文档：<a href="https://api.jquery123.com/jQuery.type/" target="_blank">jQuery.type()</a></span>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<!-- .entry-header -->
<div class="entry-content">
<article class="entry method" id="jQuery-type1"><h2 class="section-title">
<span class="name">jQuery.type( obj )</span><span class="returns">返回: <a href="/Types/#String">String</a></span>
</h2>
<div class="entry-wrapper">
<p class="desc"><strong>描述: </strong>确定JavaScript 对象的类型[[Class]] 。</p>
<ul class="signatures"><li class="signature" id="jQuery-type-obj">
<h4 class="name">
<span class="version-details">添加的版本: <a href="/category/version/1.4.3/">1.4.3</a></span>jQuery.type( obj )</h4>
<ul><li>
<div><strong>obj</strong></div>
<div>类型: <a href="/Types/#PlainObject">PlainObject</a>
</div>
<div>用来获取JavaScript数据类型[[Class]]的对象。</div>
</li></ul>
</li></ul>
<div class="longdesc" id="entry-longdesc">
<p>一些用来确定不同类型对象的数据类型。逻辑可以按以下方法确定：</p>
<ul>
<li>如果对象是undefined或null，则返回相应的“undefined”或“null”。
			        <ul>
<li>jQuery.type( undefined ) === "undefined"</li>
<li>jQuery.type() === "undefined"</li>
<li>jQuery.type( window.notDefined ) === "undefined"</li>
<li>jQuery.type( null ) === "null"</li>
</ul>
</li>
<li>如果对象有一个内部的[[Class]]和一个浏览器的内置对象的 [[Class]] 相同，我们返回相应的 [[Class]] 名字。
			
			       (<a href="http://perfectionkills.com/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/">有关此技术的更多细节。
			</a>)
			        <ul>
<li>jQuery.type( true ) === "boolean"</li>
<li>jQuery.type( 3 ) === "number"</li>
<li>jQuery.type( "test" ) === "string"</li>
<li>jQuery.type( function(){} ) === "function"</li>
<li>jQuery.type( [] ) === "array"</li>
<li>jQuery.type( new Date() ) === "date"</li>
<li>jQuery.type( new Error() ) === "error" // <strong>as of jQuery 1.9</strong>
</li>
<li>jQuery.type( /test/ ) === "regexp"</li>
</ul>
</li>
<li>其他一切都将返回它的类型“object”。</li>
</ul>
</div>
<section class="entry-examples" id="entry-examples"><header><h2 class="underline">例子:</h2></header><div class="entry-example" id="example-0">
<h4><span class="desc">找出如果该参数是一个正则表达式。</span></h4>
<div class="syntaxhighlighter xml ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
<div class="line n4">4</div>
<div class="line n5">5</div>
<div class="line n6">6</div>
<div class="line n7">7</div>
<div class="line n8">8</div>
<div class="line n9">9</div>
<div class="line n10">10</div>
<div class="line n11">11</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code><span class="doctype">&lt;!DOCTYPE html&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">html</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">head</span>&gt;</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;<span class="title">script</span> <span class="attribute">src</span>=<span class="value">"https://code.jquery.com/jquery-latest.js"</span>&gt;</span><span class="javascript"></span><span class="tag">&lt;/<span class="title">script</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">head</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">body</span>&gt;</span></code></div></div><div class="container"><div class="line"><code>  Is it a RegExp? <span class="tag">&lt;<span class="title">b</span>&gt;</span><span class="tag">&lt;/<span class="title">b</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">script</span>&gt;</span><span class="javascript">$(<span class="string">"b"</span>).append( <span class="string">""</span> + jQuery.type(<span class="regexp">/test/</span>) );</span><span class="tag">&lt;/<span class="title">script</span>&gt;</span></code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">body</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">html</span>&gt;</span></code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
<h4>Demo:</h4>
<div class="demo code-demo"></div>
</div></section>
</div></article> </div>
</article>